<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>css输入文本动画</title>
  <link rel="stylesheet" href="global.css">
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background-color: #FFCC00;
    }

    header {
      position: fixed;
      top: 0;
    }


    @keyframes cursor {

      from,
      to {
        border-color: transparent;
      }

      50% {
        border-color: black;
      }
    }

    @keyframes typing {
      from {
        width: 100%;
      }

      90%,
      to {
        width: 0;
      }
    }

    @keyframes slide {

      /* 如果有多个段落则需要前（100 % / 段落数）时间显示 */
      33.33333% {
        font-size: 3rem;
        letter-spacing: 3px;
      }

      to {
        font-size: 0;
        letter-spacing: 0;
      }
    }

    .typing-slider {
      font-family: Consolas, monospace;
      font-weight: bold;
      text-align: center;
      white-space: nowrap;
    }

    .typing-slider p {
      position: relative;
      display: inline;
      font-size: 2rem;
      text-transform: uppercase;
      letter-spacing: 0;
      /* animation: slide 12s step-start infinite; */
    }

    .typing-slider p::after {
      content: "";
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      border-left: 3px solid black;
      background-color: #FFCC00;
      animation: typing 12s infinite, cursor 0.5s infinite;
    }

    /*
    .typing-slider p:nth-child(1) {
      animation-delay: 0s;
    }
    */
    .typing-slider p:nth-child(1)::after {
      animation-delay: 0.2s;
      animation-timing-function: steps(24), step-end;
    }
  </style>
</head>

<body>
  <header>
    <a href="https://codepen.io/alewinski/pen/grqgqx">来源点击这里</a>
  </header>

  <div class="typing-slider">
    <p>床前明月光，疑是地上霜。举头望明月，低头思故乡。</p>
  </div>
</body>

</html>